﻿using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

public class ScreenEffectsForm : Form
{
    private Button btnRainbow;

    public ScreenEffectsForm()
    {
        this.Text = "屏幕特效工具";
        this.Size = new Size(300, 200);

        btnRainbow = new Button();
        btnRainbow.Text = "创建彩虹效果";
        btnRainbow.Size = new Size(150, 50);
        btnRainbow.Location = new Point(20, 20);
        btnRainbow.Click += BtnRainbow_Click;



        this.Controls.Add(btnRainbow);
    }

    private void BtnRainbow_Click(object sender, EventArgs e)
    {
        ScreenEffects.CreateRainbowEffect();
    }

    private void ScreenEffectsForm_Load(object sender, EventArgs e)
    {

    }

    private void ScreenEffectsForm_Load_1(object sender, EventArgs e)
    {

    }
}

public static class ScreenEffects
{
    [DllImport("user32.dll")]
    public static extern IntPtr GetDC(IntPtr hwnd);

    [DllImport("user32.dll")]
    public static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);

    [DllImport("gdi32.dll")]
    public static extern uint SetPixel(IntPtr hdc, int x, int y, uint color);

    public static void CreateRainbowEffect()
    {
        IntPtr desktopPtr = GetDC(IntPtr.Zero);
        Random rand = new Random();

        for (int i = 0; i < 1000; i++)
        {
            int x = rand.Next(Screen.PrimaryScreen.Bounds.Width);
            int y = rand.Next(Screen.PrimaryScreen.Bounds.Height);
            uint color = (uint)rand.Next(0xFFFFFF) | 0xFF000000;
            SetPixel(desktopPtr, x, y, color);
           
        }

        ReleaseDC(IntPtr.Zero, desktopPtr);
    }
}

// 使用方式：
// Application.Run(new ScreenEffectsForm());